﻿// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com

// ReSharper disable CheckNamespace
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable CommentTypo
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
// ReSharper disable StringLiteralTypo
// ReSharper disable UnusedParameter.Local

/* BinaryReaderExtensions.cs --
 * Ars Magna project, http://arsmagna.ru
 */

#region Using directives

using System;
using System.IO;

#endregion

#nullable enable

namespace AM.Skia.RichTextKit;

internal static class BinaryReaderExtensions
{
    public static int ReadInt32BE (this BinaryReader reader)
    {
        var bytes = reader.ReadBytes (4);
        Array.Reverse (bytes);
        return BitConverter.ToInt32 (bytes, 0);
    }

    public static uint ReadUInt32BE (this BinaryReader reader)
    {
        var bytes = reader.ReadBytes (4);
        Array.Reverse (bytes);
        return BitConverter.ToUInt32 (bytes, 0);
    }

    public static void WriteBE (this BinaryWriter writer, int value)
    {
        var bytes = BitConverter.GetBytes (value);
        Array.Reverse (bytes);
        writer.Write (bytes);
    }

    public static void WriteBE (this BinaryWriter writer, uint value)
    {
        var bytes = BitConverter.GetBytes (value);
        Array.Reverse (bytes);
        writer.Write (bytes);
    }
}
